package com.huzz.controller;

import com.huzz.model.SysUserCreateModel;
import com.huzz.model.SysUserQueryModel;
import com.huzz.model.SysUserUpdateModel;
import com.huzz.service.ISysUserService;
import com.huzz.vo.SysUserVO;
import com.huzz.util.body.DataBox;
import com.huzz.util.body.JsonResult;
import com.huzz.util.body.ResultTool;
import com.huzz.util.log.Log;
import com.huzz.util.log.LogStarter;
import com.huzz.util.log.Operate;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
* 系统用户-业务模块
*
* @author 童年的纸飞机
* @since 2023-06-06 20:05
*/
@Slf4j
@LogStarter("系统用户模块")
@RestController
@RequestMapping("/api/SysUser")
@Api(value = "系统用户模块 API", tags = {"系统用户 API"})
public class SysUserController {

    @Autowired
    private ISysUserService sysUserService;

    @Log(name = "根据id查询系统用户", operateType = Operate.SELECT)
    @ApiOperation("根据id查询系统用户")
    @GetMapping("/findSysUserById")
    public JsonResult<SysUserVO> findSysUserById(@RequestParam Integer id) {
        return ResultTool.success(sysUserService.getSysUserById(id));
    }

    @Log(name = "新建系统用户", operateType = Operate.INSERT)
    @ApiOperation("新建系统用户")
    @PostMapping("/createSysUser")
    public JsonResult createSysUser(@Validated @RequestBody SysUserCreateModel model) {
        return sysUserService.createSysUser(model) ? ResultTool.success("新建成功") : ResultTool.fail("新建失败");
    }

    @Log(name = "更新系统用户", operateType = Operate.UPDATE)
    @ApiOperation("更新系统用户")
    @PutMapping("/updateSysUser")
    public JsonResult updateSysUser(@Validated @RequestBody SysUserUpdateModel model) {
        return sysUserService.updateSysUser(model) ? ResultTool.success("更新成功") : ResultTool.fail("更新失败");
    }

    @Log(name = "根据ID删除系统用户", operateType = Operate.DELETE)
    @ApiOperation("根据ID删除系统用户")
    @DeleteMapping("/removeSysUserById")
    public JsonResult removeSysUserById(@RequestParam Integer id) {
        return sysUserService.deleteSysUserById(id) ? ResultTool.success("删除成功") : ResultTool.fail("删除失败");
    }

    @Log(name = "分页查询系统用户", operateType = Operate.SELECT)
    @ApiOperation("分页查询系统用户列表")
    @GetMapping("/querySysUserPage")
    public JsonResult querySysUserPage(@RequestParam(defaultValue = "1") Integer pageNum,
                                    @RequestParam(defaultValue = "10") Integer pageSize,
                                    @Validated SysUserQueryModel model) {
        return ResultTool.success(sysUserService.selectSysUserPage(pageNum, pageSize, model));
    }

    @Log(name = "查询系统用户列表", operateType = Operate.SELECT)
    @ApiOperation("查询系统用户列表")
    @GetMapping("/querySysUserList")
    public JsonResult querySysUserList(@Validated SysUserQueryModel model) {
        return ResultTool.success(sysUserService.selectSysUserList(model));
    }

    @Log(name = "导出系统用户", operateType = Operate.EXPORT, saveResResult = false)
    @ApiOperation("导出系统用户列表")
    @GetMapping("/exportSysUserExcel")
    public void exportSysUserExcel(HttpServletRequest request, HttpServletResponse response, @Validated SysUserQueryModel model) {
        sysUserService.exportSysUserExcel(request, response, model);
    }

    @Log(name = "批量编辑系统用户", operateType = Operate.UPDATE)
    @ApiOperation("批量编辑系统用户")
    @PutMapping("/updateSysUserByList")
    public JsonResult updateSysUserByList(@RequestBody List<SysUserUpdateModel> modelList) {
        DataBox<String> result = sysUserService.updateSysUserByList(modelList);
        return result.isSucceed() ? ResultTool.success(result.data()) : ResultTool.fail(result.data());
    }

    @Log(name = "批量删除系统用户", operateType = Operate.DELETE)
    @ApiOperation("批量删除系统用户")
    @DeleteMapping("/removeSysUserByIds")
    public JsonResult removeSysUserByIds(@RequestBody List<Integer> ids) {
        DataBox<String> result = sysUserService.deleteSysUserByIds(ids);
        return result.isSucceed() ? ResultTool.success(result.data()) : ResultTool.fail(result.data());
    }

}




































